package com.dianping.abel.response.impl;

import com.dianping.abel.enums.ResponseEnum;
import com.dianping.abel.response.Response;
import lombok.Data;

/**
 * @author xiachao
 * @date 2018/12/20
 */
@Data
public class DefaultResponse implements Response {
    private static final long serialVersionUID = 1L;

    private int code;

    private boolean success;

    private String msg;

    public DefaultResponse(boolean success){
        this.success = success;
    }

    public DefaultResponse(boolean success, String msg){
        this.success = success;
        this.msg = msg;
    }

    public DefaultResponse(int code, String msg){
        this.code = code;
        this.msg = msg;
        this.success = (code == ResponseEnum.SUCCESS.getCode());
    }

    public DefaultResponse(ResponseEnum responseEnum){
        this.code = responseEnum.getCode();
        this.msg = responseEnum.getMsg();
        this.success = (responseEnum.getCode() == ResponseEnum.SUCCESS.getCode());
    }

    @Override
    public boolean success() {
        return this.success;
    }

    @Override
    public int code() {
        return this.code;
    }

    @Override
    public String msg() {
        return this.msg;
    }
}
